package com.zyz.G_常用类.字符串;

/**
 * @author: vick
 * @Date: 2025/3/19
 * @Description:
 * @version: 1.0
 */
public class Demo3 {
    public static void main(String[] args) {
        String str1 = "321h321321";
        //获取字符串长度
        int length = str1.length();
        System.out.println(length);

        //字符串连接
        String str2 = str1 + "hhhh";
        System.out.println(str2);

        //截取字符串 [0, 5)
        String substring = str1.substring(0, 5);
        System.out.println(substring);

        //查找字符串,如果存在就返回字符串的位置，否则返回-1
        int i = str1.indexOf("h32");
        System.out.println(i);
        int i2 = str1.indexOf("sadsa");
        System.out.println(i2);

        //字符串替换, 返回一个新的字符串，替换所有出现的字符。
        String replace = str1.replace("h32", "JAVA");
        System.out.println(replace);

        //字符串转换
        //转大写
        String upperCase = str1.toUpperCase();
        System.out.println(upperCase);
        //转小写
        String lowerCase = upperCase.toLowerCase();
        System.out.println(lowerCase);

        //比较
        // equals 比较字符串内容
        boolean isEquals = str1.equals(str2);
        System.out.println(isEquals);

        //忽略大小写比较
        boolean b = str1.equalsIgnoreCase("321H321321");
        System.out.println(b);

        //通过字符串索引获取字符
        char c = str1.charAt(1);
        System.out.println(c);

        //字符串遍历
        for (int j = 0; j < str1.length(); j++) {
            System.out.println(str1.charAt(j) + " ");
        }
    }
}
